package cn.supermarket.controller;

import cn.supermarket.bean.AliPayBean;
import cn.supermarket.service.iservice.IPayService;
import com.alipay.api.AlipayApiException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api("阿里支付")
@RequestMapping("/ali")
public class AliPayController {

    /**日志对象*/
    private static final Logger logger = LoggerFactory.getLogger(AliPayController.class);

    @Autowired
    private IPayService payService;

    @ApiOperation("阿里支付")
    @PostMapping("/pay")
    @ResponseBody
    public String alipay(String outTradeNo, String subject, String totalAmount) throws AlipayApiException {

        AliPayBean alipayBean = new AliPayBean();
        alipayBean.setOut_trade_no(outTradeNo);
        alipayBean.setSubject(subject);
        alipayBean.setTotal_amount(totalAmount);
        return payService.aliPay(alipayBean);
    }

    @GetMapping("/success")
    @ResponseBody
    public String success(){
        return "交易成功！";
    }

    @GetMapping(value = "/index")
    public String payCoin(){
        return "zfindex.html";
    }


}
